/*
 * @lc app=leetcode.cn id=1656 lang=csharp
 *
 * [1656] 设计有序流
 */

// @lc code=start
public class OrderedStream {

  private int _ptr = 1;
  private string[] _values;

  public OrderedStream(int n) {
    _values = new string[n + 2];
  }
  
  public IList<string> Insert(int idKey, string value) {
    _values[idKey] = value;
    List<string> ans = new List<string>();
    if (_ptr == idKey) {
      int tmp_ptr = _ptr;
      for (; _values[tmp_ptr] != null; ++tmp_ptr) {
        ans.Add(_values[tmp_ptr]);
      }
      _ptr = tmp_ptr;
    }
    return ans;
  }
}

/**
 * Your OrderedStream object will be instantiated and called as such:
 * OrderedStream obj = new OrderedStream(n);
 * IList<string> param_1 = obj.Insert(idKey,value);
 */
// @lc code=end

